<!--
	Author: W3layouts
	Author URL: http://w3layouts.com
-->
<!DOCTYPE html>
<html lang="zxx">

<!-- Head -->

<head>

    <title>Universe Signin Form Flat Responsive Widget Template :: W3layouts</title>

    <!-- Meta-Tags -->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <!-- style CSS -->
    <link rel="stylesheet" href="css/style.css" type="text/css" media="all">
    <!-- google fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&display=swap" rel="stylesheet">
</head>
<!-- //Head -->

<!-- Body -->

<body>

    <section class="main">
        <div class="logo text-center">
            <h1> <a href="login.html"> Universe Sign In Form</a></h1>
        </div>
        <div class="content-w3ls text-center">
            <img src="images/admin.png" alt="" class="img-responsive">
            <form action="#" method="post">
                <div class="wthree-field">
                    <input name="username" id="text1" type="text" value="" placeholder="请输入用户名" required>
                </div>
                <div class="wthree-field">
                    <input name="password" id="myInput" type="Password" placeholder="请输入密码">
                </div>
                <div class="wthree-field">
                    <button type="submit" class="btn">登录</button>
                </div>
                <div class="login-bottom">
                    <a href="#url" class="">创建账户</a>
                </div>
            </form>
        </div>
        <div class="copyright">
            <p>© 2020 Universe Signin Form. Made with love | Designed by <a href="https://w3layouts.com"
                    target="_blank">W3layouts</a></p>
        </div>
    </section>
    <script src="js/jquery-3.2.1.min.js"></script>
    <script src="js/main.js"></script>
    <script>
       
        $('.btn').click(function(e){
            // 阻止默认事件
            e.preventDefault();
             // 登录向后台发送请求
            $.ajax({
                method:'POST',
                url: "http://localhost/admin/login",
                data:{
                    username: $('input[name="username"]').val(),
                    password: $('input[name="password"]').val(),
                }
                ,success:function(data){
                    if (data.code == 1) {
                        alert(data.msg);
                          var users = {
                          username: $('input[name="username"]').val(),
                          password: $('input[name="password"]').val(),
                          };

                        //   存储到本地缓存里
                    localStorage.setItem("users", JSON.stringify(users));
                    window.location.href = "/admin/backstage.html";

                    // 初始化 将数据还原
                    $('input[name="username"]').val(""),
                    $('input[name="password"]').val(""),
                    ($(".btn").checked = "");
                    }else{
                        alert(data.msg);
                    }
                }
            })
           
        })
    </script>
</body>
</html>